package com.pzy.excel;

import java.math.BigDecimal;
import java.util.Date;

import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.format.DateTimeFormat;
import cn.idev.excel.annotation.format.NumberFormat;
import cn.idev.excel.annotation.write.style.ColumnWidth;
import cn.idev.excel.annotation.write.style.ContentStyle;
import cn.idev.excel.annotation.write.style.HeadRowHeight;
import cn.idev.excel.annotation.write.style.HeadStyle;
import cn.idev.excel.enums.poi.HorizontalAlignmentEnum;
import cn.idev.excel.enums.poi.VerticalAlignmentEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ExcelIgnoreUnannotated // 生成/读取excel时,忽略未标注@ExcelProperty的字段
@HeadStyle(verticalAlignment = VerticalAlignmentEnum.CENTER, horizontalAlignment = HorizontalAlignmentEnum.CENTER)
@HeadRowHeight(25) // 设置表头行高
@ToString
public class Product {

    /**
     * excel类型为常规
     */
    @ExcelProperty(value = "分类", converter = ProductTypeConverter.class)
    private Integer type;

    /**
     * excel类型为常规
     */
    @ExcelProperty("商品名")
    @ColumnWidth(20)
    @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER)
    private String name;

    /**
     * excel类型为货币
     * ---
     * 由于加了@NumberFormat("#,##0.00")的原因, 写入时会对超出的小数部分进行四舍五入
     */
    @ExcelProperty("价格")
    @NumberFormat("#,##0.00")
    @ColumnWidth(15)
    private BigDecimal price;

    /**
     * excel类型为自定义
     */
    @ExcelProperty("生产日期")
    @DateTimeFormat("yyyy/MM/dd")
    @ColumnWidth(20)
    private Date createDate;

    @ExcelProperty("颜色和版型")
    private PrototypeAndColor prototypeAndColor;

}